package moltencore.network.protocol;

import moltencore.game.bubble.Bubble;
import spark.math.Vector2;
import spark.network.Util;
import spark.network.protocol.Base;

import java.nio.ByteBuffer;
import java.util.LinkedList;

public class CeilingPushed extends Base {
	public static final short TYPE = 0x59;
	private static final byte[] TYPE_BYTES = Util.makeBytes(TYPE);

	private long fieldId;
	private final static int FIELD_ID_LENGTH = Long.SIZE / 8;

	private Vector2 direction;
	private final static int DIRECTION_LENGTH = Vector2.SIZE / 8;

	protected static final int SIZE =
			Base.SIZE +
			FIELD_ID_LENGTH +
			DIRECTION_LENGTH;

	public CeilingPushed() {
		super(true, TYPE_BYTES);
	}

	protected CeilingPushed(boolean reliable, byte[] typeBytes) {
		super(reliable, typeBytes);
	}

	public CeilingPushed(long fieldId, Vector2 direction) {
		this();
		this.setFieldId(fieldId);
		this.setDirection(direction);
	}

	public long getFieldId() {
		return fieldId;
	}

	public void setFieldId(long fieldId) {
		this.fieldId = fieldId;
	}

	public Vector2 getDirection() {
		return direction;
	}

	public void setDirection(Vector2 direction) {
		this.direction = direction;
	}

	@Override
	public void getBytes(byte[] buffer) {
		super.getBytes(buffer);
		ByteBuffer bb = ByteBuffer.wrap(buffer, Base.SIZE, buffer.length - Base.SIZE);
		bb.put(Util.makeBytes(fieldId));
		bb.put(Util.makeBytes(direction));
	}

	@Override
	public void fill(byte[] buffer) {
		super.fill(buffer);
		ByteBuffer bb = ByteBuffer.wrap(buffer, Base.SIZE, buffer.length - Base.SIZE);
		fieldId = bb.getLong();
		setDirection(new Vector2(bb.getFloat(), bb.getFloat()));
	}

	@Override
	public int getSize() {
		return SIZE;
	}

	public static CeilingPushed create(byte[] buffer, long receiveTime) {
		CeilingPushed packet = new CeilingPushed();
		packet.fill(buffer);
		return packet;
	}
}